package com.cxkj.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxkj.dto.Meentry;
import com.cxkj.service.MeenttryService;

@Controller
@RequestMapping("/meentry")
public class MeentryController {
	
	@Autowired
	private MeenttryService meenttryService;
	
	/**
	 * 转至商户录入页面
	 * @return
	 */
	@RequestMapping("/addMeJsp")
	public String addMeJsp(){
		
		return "business-input";
	}
	/**
	 * 商户录入搜索链接
	 * @return
	 */
	@RequestMapping("/showMeByVolume")
	public String showMeByVolume(String mvolume,Model model){
	
		meenttryService.showMeByVolume(mvolume, model);
		
		return "business-input";
	}
	/**
	 * 商户录入汇总
	 * @return
	 */
	@RequestMapping("/showMeenAll")
	public String showMeenAll(String pageNow,String mvolume,String msogoname,Model model){
		
		meenttryService.showMeAll(pageNow,mvolume,msogoname,model);
		
		return "business-summary";
	}
	/**
	 * 转至商户订单信息页面
	 * @return
	 */
	@RequestMapping("/orderlist")
	public String orderlist(){
		
		return "order-list";
	}
	
	/**
	 * 转至农户录入页面
	 * @return
	 */
	@RequestMapping("/farmerJsp")
	public String farmerJsp(){
		
		return "farmer-input";
	}
	/**
	 * 农户录入信息验证金额
	 */
	@RequestMapping("farmerTest")
	@ResponseBody
	public Map<String,Object> farmerTest(String djh,String je,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		List<Meentry> list = meenttryService.farmerTest(djh, je);
		Map<String, Object> result=new HashMap<String, Object>();
		if(list.size() == 0 ){
			result.put("result", "0");
		}else{
			result.put("result", "1");
		}
		return result;
	}
	/**
	 * 由农户录入点击结算进入结算状态
	 * @return
	 */
	@RequestMapping("/settlementStatus")
	public String settlementStatus(){
		
		return "settlement-status";
	}
	/**
	 * 转至结算信息页面
	 * @return
	 */
	@RequestMapping("/settlement")
	public String settlement(HttpServletRequest request,String pageNow,Model model){
		/*SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
		String date = df.format(new Date());
		System.out.println("当前时间："+df.format(new Date()));// new Date()为获取当前系统时间
		model.addAttribute("date", date);*/
		
		meenttryService.settlement(request,pageNow, model);
		
		return "settlement";
	}
	
	
	

}
